package com.cmcc.linlaker.fragment;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.cmcc.linlaker.R;
import com.cmcc.linlaker.adapter.FilterTabAdapter;
import com.cmcc.linlaker.application.LinhuApp;
import com.cmcc.linlaker.bean.DictBean;
import com.cmcc.linlaker.bean.RoundProjectBean;
import com.cmcc.linlaker.http.ApiDefine;
import com.cmcc.linlaker.ui.query.FarmerDetailActivity;
import com.cmcc.linlaker.ui.query.ProjectDetailActivity;
import com.cmcc.linlaker.ui.query.bean.QueryProjectBean;
import com.cmcc.linlaker.utils.DensityUtil;
import com.cmcc.linlaker.utils.IntentUtils;
import com.cmcc.linlaker.utils.ToastUtils;
import com.cmcc.linlaker.utils.Utils;
import com.cmcc.linlaker.view.GridSpacingItemDecoration;
import com.cmcc.linlaker.volley.GsonRequestHelper;
import com.tianditu.android.maps.GeoPoint;
import com.tianditu.android.maps.MapController;
import com.tianditu.android.maps.MapView;
import com.tianditu.android.maps.MyLocationOverlay;
import com.tianditu.android.maps.overlay.CircleOverlay;
import com.tianditu.android.maps.overlay.MarkerOverlay;
import com.tianditu.android.maps.renderoption.CircleOption;
import com.tianditu.android.maps.renderoption.DrawableOption;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.microedition.khronos.opengles.GL10;

public class RoundFragment extends Fragment implements View.OnClickListener {
    private View fragmentView;
    private ProgressDialog progressDialog;

    public RoundFragment() {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        fragmentView = inflater.inflate(R.layout.fragment_round, container, false);

        initView();

        return fragmentView;
    }

    private RelativeLayout layout_filter;
    private LinearLayout layout_round;
    public static MapView mMapView;
    private ImageView image_location;
    private LinearLayout layout_sl, layout_yx;
    private TextView text_sl, text_yx;

    private void initView() {
        progressDialog = new ProgressDialog(getActivity());
        progressDialog.setMessage("正在加载数据，请稍等...");
        progressDialog.setCancelable(false);

        layout_sl = fragmentView.findViewById(R.id.layout_sl);
        layout_yx = fragmentView.findViewById(R.id.layout_yx);
        text_sl = fragmentView.findViewById(R.id.text_sl);
        text_yx = fragmentView.findViewById(R.id.text_yx);

        layout_filter = fragmentView.findViewById(R.id.layout_filter);
        layout_filter.setOnClickListener(this);

        layout_round = fragmentView.findViewById(R.id.layout_round);

        mMapView = fragmentView.findViewById(R.id.main_mapview);
        image_location = fragmentView.findViewById(R.id.image_location);

        resetList();
        initMap();

        layout_sl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMapView.setMapType(MapView.TMapType.MAP_TYPE_VEC);

                layout_yx.setBackgroundColor(getResources().getColor(R.color.transparent));
                layout_sl.setBackgroundColor(getResources().getColor(R.color.white));

                text_sl.setVisibility(View.VISIBLE);
                text_yx.setVisibility(View.INVISIBLE);

                isSl = !isSl;
            }
        });

        layout_yx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMapView.setMapType(MapView.TMapType.MAP_TYPE_IMG);

                layout_yx.setBackgroundColor(getResources().getColor(R.color.white));
                layout_sl.setBackgroundColor(getResources().getColor(R.color.transparent));

                text_sl.setVisibility(View.INVISIBLE);
                text_yx.setVisibility(View.VISIBLE);

                isSl = !isSl;
            }
        });

        image_location.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                resetMap();
            }
        });

        getProcessStatusList();
    }

    private boolean isSl = true;
    public static MyLocationOverlay mMyLocation;
    private GeoPoint mPoint;
    private MarkerOverlay mMarker;
    private MapController mMapController;

    private boolean isCanUpload = true;
    private int currentZoom = 13;

    private void initMap() {
        //得到mMapView的控制权,可以用它控制和驱动平移和缩放
        mMapController = mMapView.getController();
        //设置地图zoom级别
        mMapController.setZoom(13);
        //设置启用内置的缩放控件
        mMapView.setBuiltInZoomControls(false);
        mMapView.setMaxZoomLevel(15);
        mMapView.setScaleChangeListener(new MapView.OnScaleChangeListener() {
            @Override
            public void onScaleChange() {
                int zoom = mMapView.getZoomLevel();
                if (zoom >= 15) {
                    mMapController.setZoom(15);
                }

                if (zoom != currentZoom) {
                    isCanUpload = false;
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            isCanUpload = true;
                        }
                    }, 2000);
                }
                currentZoom = zoom;
            }
        });
        mMapView.setMapType(MapView.TMapType.MAP_TYPE_VEC);

        mMapView.setLogoPos(MapView.LOGO_LEFT_TOP);

        mMyLocation = new MyOverlay(getActivity(), mMapView);
        mMapView.addOverlay(mMyLocation);
        getOverlay().enableMyLocation();

        resetMap();
    }

    /**
     * 重新定位到原点
     */
    private void resetMap() {
        if (mMarker != null) {
            mMapView.removeOverlay(mMarker);
        }

        if (overlay != null) {
            mMapView.removeOverlay(overlay);
        }
        drawCenter();

        getProjectList(mPoint);
    }

    /**
     * 绘制中心点
     */
    private void drawCenter() {
        DrawableOption option = new DrawableOption();
        option.setAnchor(0.5f, 1.0f);
        mMarker = new MarkerOverlay();
        mMarker.setOption(option);
        mMarker.setIcon(getResources().getDrawable(R.mipmap.location_icon));
        mMapView.addOverlay(mMarker);

        //用给定的经纬度构造一个GeoPoint，单位是微度 (度 * 1E6)
        mPoint = new GeoPoint((int) (LAT * 1E6), (int) (LON * 1E6));
        mMarker.setPosition(mPoint);
        //设置地图中心点
        mMapController.setCenter(mPoint);
        addCircle(LON, LAT);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private MyLocationOverlay getOverlay() {
        return mMyLocation;
    }

    private GeoPoint lastGeoPoint;

    class MyOverlay extends MyLocationOverlay {
        public MyOverlay(Context context, MapView mapView) {
            super(context, mapView);
        }

        /*
         * 处理在"我的位置"上的点击事件
         */
        protected boolean dispatchTap() {
            return true;
        }

        private long mExitTime;

        @Override
        public void onLocationChanged(Location location) {
            super.onLocationChanged(location);

            if ((System.currentTimeMillis() - mExitTime) > 2000) {// 如果两次按键时间间隔大于2000毫秒，则不退出
                mExitTime = System.currentTimeMillis();// 更新mExitTime

                GeoPoint geoPoint = mMapView.getMapCenter();
                if (lastGeoPoint != null) {
                    if (lastGeoPoint.getLongitudeE6() != geoPoint.getLongitudeE6() && lastGeoPoint.getLatitudeE6() != geoPoint.getLatitudeE6()) {
                        if (isCanUpload) {
                            getProjectList(geoPoint);
                        }
                    }
                } else {
                    if (isCanUpload) {
                        getProjectList(geoPoint);
                    }
                }
                lastGeoPoint = geoPoint;
            }
        }

        @Override
        protected void drawMyLocation(GL10 gl, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
//            //获得屏幕坐标
//            Point point = new Point();
//            mapView.getProjection().toPixels(myLocation, point);
//            //默认精度
//            float accuracy = getAccuracy();
//            //指定精度float accuracy = 500;
//            //获得实际误差距离
//            float distance = mapView.getProjection().metersToEquatorPixels(accuracy);
//            AndroidJni.OpenglFillRound(point.x, point.y, (int) distance, 0, 360, 137, 170, 213, 77);
//            //创建Drawable
//            UtilTextureDrawable drawable = new UtilTextureDrawable(getActivity(), R.mipmap.location_icon, BOUND_TYPE_CENTER);
//            drawable.DrawTexture(gl, point, 0.0F);
        }
    }

    public static boolean isEnterModifyAddress = false;

    @Override
    public void onResume() {
        super.onResume();

        if (isEnterModifyAddress) {
            isEnterModifyAddress = false;

            mMapView = fragmentView.findViewById(R.id.main_mapview);
            initMap();
        } else {
            if (!mMyLocation.isCompassEnabled()) {
                mMyLocation.enableCompass();
            }

            if (!mMyLocation.isMyLocationEnabled()) {
                mMyLocation.enableMyLocation();
            }

        }

    }

    @Override
    public void onPause() {
        super.onPause();

        if (mMyLocation.isCompassEnabled()) {
            mMyLocation.disableCompass();
        }

        if (mMyLocation.isMyLocationEnabled()) {
            mMyLocation.disableMyLocation();
        }
    }

    public void refreshMap() {
        if (mMapView != null) {
            mMapView.postInvalidate();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_filter:
                filter();
                break;
        }
    }

    /**
     * 筛选
     */
    private void filter() {
        showFilterTab(layout_round);
    }

    /**
     * 筛选条件选择
     */
    private PopupWindow popupWindow;

    private void showFilterTab(View view) {
        if (popupWindow != null && popupWindow.isShowing()) {
            return;
        }

        RelativeLayout layout = (RelativeLayout) getLayoutInflater().inflate(R.layout.filter_page, null);
        popupWindow = new PopupWindow(layout,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        // 产生背景变暗效果
//        WindowManager.LayoutParams lp = getActivity().getWindow()
//                .getAttributes();
//        lp.alpha = 0.4f;
//        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
//        getActivity().getWindow().setAttributes(lp);

        //点击空白处时，隐藏掉pop窗口
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        //添加弹出、弹入的动画
        popupWindow.setAnimationStyle(R.style.Popupwindow);
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        popupWindow.showAtLocation(view, Gravity.RIGHT | Gravity.TOP, -location[0], 0);
//        popupWindow.showAtLocation(view, Gravity.LEFT | Gravity.BOTTOM, 0, -location[1]);
        //添加按键事件监听
        setButtonListeners(layout);

//        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//
//            // 在dismiss中恢复透明度
//            public void onDismiss() {
//                WindowManager.LayoutParams lp = getActivity().getWindow()
//                        .getAttributes();
//                lp.alpha = 1f;
//                getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
//                getActivity().getWindow().setAttributes(lp);
//            }
//        });
    }

    /**
     * 重置
     */
    private void resetList() {
        processStatusPosition = -1;
        usingAttributesPosition = -1;
        typePosition = -1;

        for (int i = 0; i < processStatusList.size(); i++) {
            processStatusList.get(i).isSelected = false;
        }

        for (int i = 0; i < LinhuApp.usingAttributesList.size(); i++) {
            LinhuApp.usingAttributesList.get(i).isSelected = false;
        }

        for (int i = 0; i < LinhuApp.typeList.size(); i++) {
            LinhuApp.typeList.get(i).isSelected = false;
        }
    }

    private FilterTabAdapter approveAdapter, propertyAdapter, serviceAdapter;
    //办理状态process_status  使用属性using_attributes  项目类型project_type

    private void setButtonListeners(RelativeLayout layout) {
        RelativeLayout layout_pop = layout.findViewById(R.id.layout_pop);
        layout_pop.getLayoutParams().width = (int) (DensityUtil.getScreenWidth(getActivity()) * 4 / 5f);

        RecyclerView recycler_approve = layout.findViewById(R.id.recycler_approve);
        setRecyclerViewApprove(recycler_approve, processStatusList);

        RecyclerView recycler_property = layout.findViewById(R.id.recycler_property);
        setRecyclerViewProperty(recycler_property, LinhuApp.usingAttributesList);

        RecyclerView recycler_service = layout.findViewById(R.id.recycler_service);
        setRecyclerViewService(recycler_service, LinhuApp.typeList);

        TextView text_reset = layout.findViewById(R.id.text_reset);
        TextView text_finish = layout.findViewById(R.id.text_finish);

        text_reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();

                resetList();

                approveAdapter.notifyDataSetChanged();
                propertyAdapter.notifyDataSetChanged();
                serviceAdapter.notifyDataSetChanged();

                getProjectList(lastGeoPoint);
            }
        });

        text_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();

                getProjectList(lastGeoPoint);
            }
        });
    }

    private int processStatusPosition = -1;
    private int usingAttributesPosition = -1;
    private int typePosition = -1;

    private void setRecyclerViewApprove(RecyclerView recycler_view, List<DictBean.DictData> itemList) {
        recycler_view.setHasFixedSize(true);
        recycler_view.setLayoutManager(new GridLayoutManager(getActivity(), 3));

        recycler_view.setNestedScrollingEnabled(false);
        recycler_view.addItemDecoration(new GridSpacingItemDecoration(3, DensityUtil.dip2px(getActivity(), 10), true));

        approveAdapter = new FilterTabAdapter(getActivity(), itemList);
        approveAdapter.setOnItemClickListener(new FilterTabAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                processStatusPosition = position;
                approveSelected(position);
            }
        });
        recycler_view.setAdapter(approveAdapter);
    }

    private void approveSelected(int position) {
        if (!processStatusList.get(position).isSelected) {
            processStatusPosition = position;
            for (int i = 0; i < processStatusList.size(); i++) {
                if (position == i) {
                    processStatusList.get(i).isSelected = true;
                } else {
                    processStatusList.get(i).isSelected = false;
                }
            }

        } else {
            processStatusPosition = -1;
            processStatusList.get(position).isSelected = false;
        }

        approveAdapter.notifyDataSetChanged();

    }

    private void setRecyclerViewProperty(RecyclerView recycler_view, List<DictBean.DictData> itemList) {
        recycler_view.setHasFixedSize(true);
        recycler_view.setLayoutManager(new GridLayoutManager(getActivity(), 3));

        recycler_view.setNestedScrollingEnabled(false);
        recycler_view.addItemDecoration(new GridSpacingItemDecoration(3, DensityUtil.dip2px(getActivity(), 10), true));

        propertyAdapter = new FilterTabAdapter(getActivity(), itemList);
        propertyAdapter.setOnItemClickListener(new FilterTabAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {

                propertySelected(position);
            }
        });
        recycler_view.setAdapter(propertyAdapter);
    }

    private void propertySelected(int position) {
        if (!LinhuApp.usingAttributesList.get(position).isSelected) {
            usingAttributesPosition = position;
            for (int i = 0; i < LinhuApp.usingAttributesList.size(); i++) {
                if (position == i) {
                    LinhuApp.usingAttributesList.get(i).isSelected = true;
                } else {
                    LinhuApp.usingAttributesList.get(i).isSelected = false;
                }
            }

        } else {
            usingAttributesPosition = -1;
            LinhuApp.usingAttributesList.get(position).isSelected = false;
        }
        propertyAdapter.notifyDataSetChanged();
    }

    private void setRecyclerViewService(RecyclerView recycler_view, List<DictBean.DictData> itemList) {
        recycler_view.setHasFixedSize(true);
        recycler_view.setLayoutManager(new GridLayoutManager(getActivity(), 3));

        recycler_view.setNestedScrollingEnabled(false);
        recycler_view.addItemDecoration(new GridSpacingItemDecoration(3, DensityUtil.dip2px(getActivity(), 10), true));

        serviceAdapter = new FilterTabAdapter(getActivity(), itemList);
        serviceAdapter.setOnItemClickListener(new FilterTabAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                serviceSelected(position);
            }
        });
        recycler_view.setAdapter(serviceAdapter);
    }

    private void serviceSelected(int position) {
        if (!LinhuApp.typeList.get(position).isSelected) {
            typePosition = position;
            for (int i = 0; i < LinhuApp.typeList.size(); i++) {
                if (position == i) {
                    LinhuApp.typeList.get(i).isSelected = true;
                } else {
                    LinhuApp.typeList.get(i).isSelected = false;
                }
            }

        } else {
            typePosition = -1;
            LinhuApp.typeList.get(position).isSelected = false;
        }
        serviceAdapter.notifyDataSetChanged();
    }

    private List<DictBean.DictData> processStatusList = new ArrayList<>();

    private void getProcessStatusList() {
        for (DictBean.DictData dictData : LinhuApp.processStatusList) {
            if (!dictData.dictLabel.equals("未通过")) {

                if (dictData.dictLabel.equals("已通过")) {
                    DictBean.DictData dictDataNew = new DictBean.DictData();
                    dictDataNew.dictLabel = "已审批";
                    dictDataNew.dictValue = dictData.dictValue;
                    processStatusList.add(dictDataNew);
                }

//                else if (dictData.dictLabel.equals("待审批")) {
//                    dictDataNew.dictLabel = "未审批";
//                    dictDataNew.dictValue = dictData.dictValue;
//                }

            } else {
                DictBean.DictData dictDataNew = new DictBean.DictData();

                dictDataNew.dictLabel = "未审批";
                dictDataNew.dictValue = dictData.dictValue;

                processStatusList.add(dictDataNew);
            }
        }
    }

    private List<RoundProjectBean.QueryProjectData> projectList = new ArrayList<>();

    /**
     * 获取项目列表
     * processStatusPosition ,usingAttributesPosition ,typePosition
     */
    private void getProjectList(GeoPoint geoPoint) {
        if (geoPoint == null) {
            geoPoint = new GeoPoint((int) (LAT * 1E6), (int) (LON * 1E6));
        } else if (geoPoint.getLatitudeE6() == 0 || geoPoint.getLongitudeE6() == 0) {
            geoPoint = new GeoPoint((int) (LAT * 1E6), (int) (LON * 1E6));
        }

        GsonRequestHelper helper = new GsonRequestHelper(getActivity());
        Map<String, String> params = new HashMap<>();
        params.put("distance", "5");
        params.put("latitude", Utils.formatLatLng((float) (geoPoint.getLatitudeE6() / 1E6)));
        params.put("longitude", Utils.formatLatLng((float) (geoPoint.getLongitudeE6() / 1E6)));
        if (processStatusPosition != -1) {
            params.put("processStatus", processStatusList.get(processStatusPosition).dictValue);
        }
        if (typePosition != -1) {
            params.put("type", LinhuApp.typeList.get(typePosition).dictValue);
        }
        if (usingAttributesPosition != -1) {
            params.put("usingAttributes", LinhuApp.usingAttributesList.get(usingAttributesPosition).dictValue);
        }
        helper.sendPOSTRequest(ApiDefine.PROJECT_LIST1, RoundProjectBean.class, params, true, null);
        helper.setOnResponseListener(new GsonRequestHelper.OnResponseListener() {
            @Override
            public void onError(VolleyError error) {

            }

            @Override
            public void onSuccess(Object data) {
                if (data != null) {
                    RoundProjectBean bean = (RoundProjectBean) data;

                    if (bean.code.equals("0")) {
                        if (bean.rows != null) {
                            projectList.clear();
                            projectList.addAll(bean.rows);
                            addOverLay();
                        } else {
                            projectList.clear();
                            addOverLay();
                        }
                    } else if (bean.code.equals(IntentUtils.VAILD_CODE)) {
                        IntentUtils.skipToLogin(getActivity());
                    } else {
                        ToastUtils.showText(getActivity(), bean.msg);
                    }
                }
            }
        });
    }

    /**
     * 添加覆盖物
     */
    private void addOverLay() {

        clearMarket();

        for (int i = 0; i < projectList.size(); i++) {
            RoundProjectBean.QueryProjectData projectData = projectList.get(i);
            String process_status = projectData.process_status;
            String industry = projectData.industry;
            int lat = (int) (Float.parseFloat(projectData.latitude) * 1E6);
            int lng = (int) (Float.parseFloat(projectData.longitude) * 1E6);
            GeoPoint mPoint = new GeoPoint(lat, lng);
            MarkerOverlay overlay = null;

            if (process_status.equals("1")) {
                //已通过
                if (!TextUtils.isEmpty(industry)) {
                    if (industry.equals("山水林田湖草")) {
                        //属性
                        overlay = getMaker(i, R.mipmap.shyg, mPoint);
                    } else if (industry.equals("农民建房")) {
                        overlay = getMaker(i, R.mipmap.wshb_green_icon, mPoint);
                    } else {
                        overlay = getMaker(i, R.mipmap.ysh2_icon, mPoint);
                    }
                } else {
                    overlay = getMaker(i, R.mipmap.wshb_green_icon, mPoint);
                }

            } else {
                //未通过
                if (!TextUtils.isEmpty(industry)) {
                    if (industry.equals("山水林田湖草")) {
                        //属性
                        overlay = getMaker(i, R.mipmap.shwg, mPoint);
                    } else if (industry.equals("农民建房")) {
                        overlay = getMaker(i, R.mipmap.wshb_red_icon, mPoint);
                    } else {
//                        overlay = getMaker(i, R.mipmap.wsh2_icon, mPoint);
                        overlay = getMaker(i, R.mipmap.yichang, mPoint);
                    }
                } else {
                    overlay = getMaker(i, R.mipmap.yichang, mPoint);
                }
            }
            if (overlay != null) {
                addMarker(mMapView, overlay);
            } else {
                overlay = getMaker(i, R.mipmap.ysh2_icon, mPoint);
                addMarker(mMapView, overlay);
            }
            markerOverlayList.add(overlay);
        }

    }

    private void addMarker(final MapView mMapView, final MarkerOverlay overlay) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                mMapView.addOverlay(overlay);
            }
        });
    }

    Handler handler = new Handler();

    private void clearMarket() {
        for (MarkerOverlay markerOverlay : markerOverlayList) {
            mMapView.removeOverlay(markerOverlay);
        }
        markerOverlayList.clear();
    }

    private List<MarkerOverlay> markerOverlayList = new ArrayList<>();
    public static boolean isCanClick = true;

    private MarkerOverlay getMaker(final int position, int res, GeoPoint mPoint) {
        DrawableOption option = new DrawableOption();
        option.setAnchor(0.5f, 1.0f);
        MarkerOverlay mMarker = new MarkerOverlay();
        mMarker.setOption(option);
        mMarker.setIcon(getResources().getDrawable(res));
        mMarker.setPosition(mPoint);
        mMarker.setClickListener(new MarkerOverlay.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(MarkerOverlay markerOverlay) {
                if (isCanClick) {
                    isCanClick = false;
                    if (!TextUtils.isEmpty(projectList.get(position).type)) {
                        if (!projectList.get(position).type.equals("-1")) {
                            QueryProjectBean.QueryProjectData projectData = new QueryProjectBean.QueryProjectData();
                            projectData.id = projectList.get(position).id;

                            Intent intent = new Intent(getActivity(), ProjectDetailActivity.class);
                            intent.putExtra("projectData", projectData);
                            intent.putExtra("flag", 1);
                            startActivity(intent);
                        } else {
                            QueryProjectBean.QueryProjectData houseData = new QueryProjectBean.QueryProjectData();
                            houseData.id = projectList.get(position).id;

                            Intent intent = new Intent(getActivity(), FarmerDetailActivity.class);
                            intent.putExtra("houseData", houseData);
                            intent.putExtra("flag", 1);
                            startActivity(intent);
                        }
                    } else {
                        QueryProjectBean.QueryProjectData projectData = new QueryProjectBean.QueryProjectData();
                        projectData.id = projectList.get(position).id;

                        Intent intent = new Intent(getActivity(), ProjectDetailActivity.class);
                        intent.putExtra("projectData", projectData);
                        intent.putExtra("flag", 1);
                        startActivity(intent);
                    }
                }
                return false;
            }
        });
        return mMarker;
    }

    final double LON = 119.041202; // 起始经度
    final double LAT = 29.611058; // 起始纬度
    private CircleOverlay overlay;

    /**
     * 圆形
     */
    private void addCircle(double dLon, double dLat) {
        GeoPoint point = new GeoPoint((int) (dLat * 1E6), (int) (dLon * 1E6));

        CircleOption option = new CircleOption();
        option.setFillColor(0x440091FF);
        option.setStrokeWidth(1);
        option.setStrokeColor(0xFF3A9CE6);

        overlay = new CircleOverlay();
        overlay.setOption(option);
        overlay.setCenter(point);
        overlay.setRadius(2000);
        mMapView.addOverlay(overlay);
    }


}
